package com.thor.palmmall.rest.order.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.palmmall.rest.order.AAmountActivities;
import com.thor.palmmall.rest.order.AGiftActivies;
import com.thor.palmmall.rest.order.AProductProm3;
import com.thor.palmmall.spi.order.SProductProm3;

public class AProductProm3Converter implements Converter<SProductProm3, AProductProm3> {
  private static AProductProm3Converter instance;

  public static AProductProm3Converter getInstance() {
    if (instance == null)
      instance = new AProductProm3Converter();
    return instance;
  }

  private AProductProm3Converter() {
  }

  @Override
  public AProductProm3 convert(SProductProm3 source) {
    if (source == null) {
      return null;
    }
    AProductProm3 target = new AProductProm3();

    if (source.getAmountActivities() != null) {
      target.setAmountActivities(
          AAmountActivitiesConverter.getInstance().convert(source.getAmountActivities()));
    } else {
      target.setAmountActivities(new ArrayList<AAmountActivities>());
    }

    if (source.getGiftActivies() != null) {
      target
          .setGiftActivies(AGiftActiviesConverter.getInstance().convert(source.getGiftActivies()));
    } else {
      target.setGiftActivies(new ArrayList<AGiftActivies>());
    }

    return target;
  }

}
